package com.czy.form.util;

import java.util.HashMap;

/***
 * @ ClassName: ResultMap
 * @ Description: TODO
 * @ author：libi
 * @ date： 2020/2/4 12:33
 * @ version： V1.0.0
 * @ CopyRight：czy
 */
public class ResultMap extends HashMap {

    private boolean res;
    private String code;
    private String msg;
    private Object data;

    public ResultMap() {

    }

    public ResultMap(ResultEnum resultEnum) {
        this.res = ResultEnum.SUCCESS.getCode().equals(resultEnum.getCode());
        this.code = resultEnum.getCode();
        this.msg = resultEnum.getMsg();
        this.put("res", res);
        this.put("msg", msg);
        this.put("code", code);
    }

    public ResultMap(boolean res, String code, String msg) {
        this.res = res;
        this.code = code;
        this.msg = msg;
        this.put("res", res);
        this.put("msg", msg);
        this.put("code", code);
    }

    public static ResultMap success(){
        return new ResultMap(ResultEnum.SUCCESS);
    }

    public static ResultMap failure(){
        return new ResultMap(ResultEnum.FAILURE);
    }

    public static ResultMap failure(String msg){
        return new ResultMap(ResultEnum.FAILURE).setMsg(msg);
    }


    public boolean isRes() {
        return res;
    }

    public ResultMap setRes(boolean res) {
        this.res = res;
        this.put("res", res);
        return this;
    }

    public String getCode() {
        return code;
    }

    public ResultMap setCode(String code) {
        this.code = code;
        this.put("code", code);
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public ResultMap setMsg(String msg) {
        this.msg = msg;
        this.put("msg", msg);
        return this;
    }

    public Object getData() {
        return data;
    }

    public ResultMap setData(Object data) {
        this.data = data;
        this.put("data", data);
        return this;
    }


}
